package com.lzy.mall.member.web;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import com.lzy.mall.common.utils.ResultUtils;
import com.lzy.mall.member.feign.OrderFeignService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @author lzy
 * @date 2021/10/13 11:02
 */
@Controller
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
@Slf4j
public class MemberWeb {

    private final OrderFeignService orderFeignService;

    @GetMapping("/memberOrder.html")
    public String memberOrderPage(@RequestParam(required = false, defaultValue = "1") Long pageNum, Model model){
        if (ObjectUtil.isNull(pageNum)){
            pageNum = 1L;
        }
        ResultUtils result = orderFeignService.listWithItem(pageNum);
        log.info("订单远程调用列表：{}", JSONUtil.toJsonStr(result));
        model.addAttribute("orders",result);
        return "orderList";
    }
}
